/*
 * qr_test.c
 *
 *  Created on: Feb 24, 2024
 *      Author: Shaynerain
 */

#include "qr_encode.h"
#include "main.h"
#include "EPD_App.h"

#include "qr_App.h"


void qr_2_lcd(uint8_t *bit_buf, uint16_t width, uint16_t x, uint16_t y)
{
	uint16_t i,j, index, w, h;

	uint16_t scale=2;

//	Paint_DrawRectangle(10, 10, 200, 150, WHITE, 1, DRAW_FILL_FULL);

	for(i=0; i<width; i++)
	{
		for(j=0; j<width; j++)
		{
			index = j*width+i;
			if(bit_buf[index/8]&(1<<(7-index%8)))
			{
				for(w=0; w<scale; w++)
				{
					for(h=0; h<scale; h++)
					{
						Paint_DrawPoint(scale*i + w + x, scale*j + h + y, BLACK, DOT_PIXEL_1X1, DOT_FILL_AROUND);
					}
				}
			}
		}
	}

//    EPD_3IN52_display(BIT_MAP);
//    EPD_3IN52_refresh();
}



int8_t generator_qr(uint8_t* str, uint16_t x, uint16_t y)
{
	uint16_t width;
	uint8_t* bit_buf = malloc(QR_MAX_BITDATA);
	if(bit_buf == NULL)
	{
		printf("qr malloc error\n");
		return -1;
	}
	else
	{
		width = qr_encode(QR_LEVEL_M, 0, (char*)str, 0, bit_buf);

		qr_2_lcd(bit_buf, width, x, y);
		free(bit_buf);
		return 0;
	}

}

